﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web.Mvc;
using System.Xml.Serialization;

namespace yao.Mvc
{
    public class IframeResult : ActionResult
    {
        public IframeResult(string fromUrl, string toUrl)
        {
            FromUrl = fromUrl;
            ToUrl = toUrl;
        }

        public string FromUrl { get; set; }
        public string ToUrl { get; set; }

        public override void ExecuteResult(ControllerContext context)
        {
            if (string.IsNullOrEmpty(FromUrl) || string.IsNullOrEmpty(ToUrl))
            {
                new EmptyResult().ExecuteResult(context);
                return;
            }
            context.HttpContext.Response.ContentType = "text/html";
            context.HttpContext.Response.Output.Write("<script src =\"/script/jquery1.9.0.min.js\"></script>");
            context.HttpContext.Response.Output.Write("<script src =\"/script/g.js?v="+ WebConfig.Version + "\"></script>");
            context.HttpContext.Response.Output.Write("<script>$.closeform({formUrl: \""+FromUrl+"\",listUrl: \""+ToUrl+"\"});</script>");
            //using (MemoryStream ms = new MemoryStream())
            //{
            //    XmlSerializer xs = new XmlSerializer(Data.GetType());
            //    xs.Serialize(ms, Data);
            //    ms.Position = 0;
            //    using (StreamReader sr = new StreamReader(ms))
            //    {
            //        context.HttpContext.Response.Output.Write(sr.ReadToEnd());
            //    }
            //}
        }
    }
}
